package cate.game.role.farm.adventure;

import cate.common.table.d.GDFight;
import cate.common.table.d.GDOperation;
import cate.common.table.farm.adventure.row.AdventureBossRow;
import cate.game.client.msg.MergeMsgSender;
import cate.game.play.proce.play.PlayPO;
import cate.game.play.vo.PlayReportVO;
import cate.game.res.MixRes;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;
import cate.game.role.farm.adventure.msg.AdventureBossResultResp;
import cate.game.role.farm.adventure.msg.AdventureDataResp;

public class AdventureBossFTC extends AbstractFarmFTC<AdventureBoss> {

    /**
     * 当前挑战的战斗关卡模板
     */
    private final AdventureBossRow tpl;

    public AdventureBossFTC(Role role, AdventureBossRow tpl) {
        setup(role);
        this.tpl = tpl;
    }

    @Override
    protected AdventureBoss po(Role role) {
        return role.getFarm().adventure.boss;
    }

    @Override
    public void handleResult(Role role, PlayPO playPO) {
        super.handleResult(role, playPO);
        boolean win = playPO.winner == GDFight.Team.A;
        MixRes reward = null;
        MergeMsgSender sender = new MergeMsgSender();
        AdventureBoss po = po(role);
        if (win) {
            //打完了
            po.changeBossIdPassed(tpl.id);
            role.log.setOperation(GDOperation.ADVENTURE_CHALLENGE);
            reward = new MixRes(tpl.rewardStr);
            reward.add(role, sender);
            role.log.clearOperation();
            role.send(new AdventureDataResp(role));
            role.getHistory().action.adventureBossKill();
        }
        AdventureBossResultResp result = new AdventureBossResultResp(tpl.id, win, reward, true);
        result.report = new PlayReportVO(playPO);
        role.sendNow(result);
        sender.send(role, true);
    }
}
